use log::info;

trait Animal {
    type Level;
    fn level_name() -> &'static str;
}

trait Mammal: Animal {
    type Level;
    fn level_name() -> &'static str;

    fn walk(&self);
}

trait Canine: Mammal {
    type Level;
    fn level_name() -> &'static str;

    fn bark(&self);
}

// 层级类型
struct AnimalLevel;
struct MammalLevel;
struct CanineLevel;

struct Dog;

impl Animal for Dog {
    type Level = AnimalLevel;
    fn level_name() -> &'static str {
        "animal"
    }
}

impl Mammal for Dog {

    type Level = MammalLevel;
    fn level_name() -> &'static str {
        "mammal"
    }
    fn walk(&self) {
        info!("Walking");
    }
}

impl Canine for Dog {
    type Level = CanineLevel;
    fn level_name() -> &'static str {
        "canine"
    }

    fn bark(&self) {
        info!("Barking");
    }
}

// 编译时判断层级的函数
fn print_hierarchy<T: Animal>() {
    info!("This is at level: {}", T::level_name());
}

#[test]
fn main() {
    print_hierarchy::<Dog>(); // 输出: This is at level: Canine
}